#include "test2.h"

// -----------------------------------------------------------------------------
void
tenacitas::balance_line::test2::
run( ) {

    f0( ) ;
}

const char * say_what(bool b) { return b ? "true" : "false"; }        

// -----------------------------------------------------------------------------
void
tenacitas::balance_line::test2::
f0( ) {
    logger l_log;

    // generating log
    std::int16_t l_count_stop = 0;
    for ( std::int16_t l_i = 0; l_i < 100; ++l_i ) {
        ++l_count_stop;
        if ( l_count_stop == 10 ) {
            std::this_thread::sleep_for( std::chrono::milliseconds( 400 ) );
            l_count_stop = 0;
        }
        log_trace( l_log ) << "counter = " << l_i;
    }

    // merging log


    filesystem::directory_iterator l_dir_begin( "./" );
    
    filesystem::directory_iterator l_dir_end;

    for( filesystem::directory_iterator l_dir_ite = l_dir_begin; l_dir_ite !=
             l_dir_end; ++l_dir_ite ) {
        std::string l_filename = l_dir_ite->path( ).filename( ).string( );
        std::string::size_type l_size = l_filename.size( );
        
        if (
            ( l_size > 5 ) &&
            ( l_filename[l_size - 1] == 'D' ) &&
            ( l_filename[l_size - 2] == 'N' ) &&
            ( l_filename[l_size - 3] == 'E' ) &&
            ( l_filename[l_size - 4] == '.' ) ) {
            std::cout << l_filename << ", ";

            std::string::size_type l_end = l_size - 8;

            std::string::size_type l_pos = l_end;
            for ( ; l_filename[l_pos] != '_'; --l_pos ) {
                ;
            }
            ++l_pos;
                        

            std::string l_index_str ( &l_filename[l_pos], &l_filename[l_end] );
            std::cout << l_index_str << ", ";

            std::uint64_t l_index = std::stoull( l_index_str );
            std::cout << l_index << "\n";
            
        }        
    }
    
    
    // std::cout << "\nelements:\n";

    // for (filesystem::path::iterator it(p.begin()), it_end(p.end()); it != it_end; ++it)
    //     std::cout << "  " << *it << '\n';

//     std::cout  <<  "\nobservers, native format:" << endl;
// # ifdef BOOST_POSIX_API
//     std::cout  <<  "  native()-------------: " << p.native() << endl;
//     std::cout  <<  "  c_str()--------------: " << p.c_str() << endl;
// # else  // BOOST_WINDOWS_API
//     wstd::cout << L"  native()-------------: " << p.native() << endl;
//     wstd::cout << L"  c_str()--------------: " << p.c_str() << endl;
// # endif
//     std::cout  <<  "  string()-------------: " << p.string() << endl;
// //    wstd::cout << L"  wstring()------------: " << p.wstring() << endl;

//     std::cout  <<  "\nobservers, generic format:\n";
//     std::cout  <<  "  generic_string()-----: " << p.generic_string() << endl;
// //    wstd::cout << L"  generic_wstring()----: " << p.generic_wstring() << endl;

//     std::cout  <<  "\ndecomposition:\n";
//     std::cout  <<  "  root_name()----------: " << p.root_name() << '\n';
//     std::cout  <<  "  root_directory()-----: " << p.root_directory() << '\n';
//     std::cout  <<  "  root_path()----------: " << p.root_path() << '\n';
//     std::cout  <<  "  relative_path()------: " << p.relative_path() << '\n';
//     std::cout  <<  "  parent_path()--------: " << p.parent_path() << '\n';
//     std::cout  <<  "  filename()-----------: " << p.filename() << '\n';
//     std::cout  <<  "  stem()---------------: " << p.stem() << '\n';
//     std::cout  <<  "  extension()----------: " << p.extension() << '\n';

//     std::cout  <<  "\nquery:\n";
//     std::cout  <<  "  empty()--------------: " << say_what(p.empty()) << '\n';
//     std::cout  <<  "  is_absolute()--------: " << say_what(p.is_absolute()) << '\n';
//     std::cout  <<  "  has_root_name()------: " << say_what(p.has_root_name()) << '\n';
//     std::cout  <<  "  has_root_directory()-: " << say_what(p.has_root_directory()) << '\n';
//     std::cout  <<  "  has_root_path()------: " << say_what(p.has_root_path()) << '\n';
//     std::cout  <<  "  has_relative_path()--: " << say_what(p.has_relative_path()) << '\n';
//     std::cout  <<  "  has_parent_path()----: " << say_what(p.has_parent_path()) << '\n';
//     std::cout  <<  "  has_filename()-------: " << say_what(p.has_filename()) << '\n';
//     std::cout  <<  "  has_stem()-----------: " << say_what(p.has_stem()) << '\n';
//     std::cout  <<  "  has_extension()------: " << say_what(p.has_extension()) << '\n';
    

}
